package cn.wolfcode.p2p.base.util;

import java.util.Calendar;
import java.util.Date;

public abstract class DateUtil {
    //获取当前的最后时间
    public static Date getEndDate(Date d) {
        if (d == null) {
            return null;
        }
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        c.set(Calendar.HOUR,23);
        c.set(Calendar.MINUTE,59);
        c.set(Calendar.SECOND,59);
        return c.getTime();
    }

    /**
     * 获取两个时间间隔的秒数
     * @param t1
     * @param t2
     * @return  abs 绝对值
     */
    public static Long getTimeBetween(Date t1,Date t2){
        return Math.abs((t1.getTime()-t2.getTime())/1000);
    }

    public static Date getBeginDate(Date date) {
        if (date == null) {
            return null;
        }
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        return c.getTime();
    }
}
